
/***********************************************************************
 * Orbit class
 * 
 * Implements the 'orbit' command
 *
 * Signature:
 *  public static Orbit create ();
 *  public String name ();
 *  public boolean execute (String[] arguments);
 ***********************************************************************/

public class Orbit extends Command {

    protected Orbit () {
	super("orbit");
    }

    public static Orbit create () {
	return new Orbit();
    }

    private static Option<Artifact> findArtifactAroundPosition (Coord c) {
	for (Artifact art : SpaceGame.map())
	    if (art.position().within(c.move(-1,-1),c.move(1,1)) && !art.position().equals(c))
		return Option.some(art);
	return Option.none();
    }

    public boolean execute (String[] args) {
	Option<Artifact> toOrbit = findArtifactAroundPosition(SpaceGame.me().position());
	if (toOrbit.isNone()) {
	    System.out.println("Nothing to orbit");
	    return false;
	}
	SpaceGame.me().orbit(toOrbit.valOf());
	return true;
    }

}